package com.chzc.fm.duotin.adapter.listview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chzc.fm.duotin.R;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/6/30.
 */
public class TrackListAdapter extends BaseAdapter {

    private Context context;
    private List<Map<String , Object>> listItems;
    private LayoutInflater inflater;

    public TrackListAdapter(Context context, List<Map<String, Object>> listItems) {
        this.context = context;
        this.listItems = listItems;
        inflater =LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return listItems.size();
    }

    @Override
    public Object getItem(int position) {
        return listItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = new ViewHolder();
        if(convertView == null)
        {
            convertView = inflater.inflate(R.layout.listview_item,null,false);

            holder.title = (TextView) convertView.findViewById(R.id.listview_item_title_tv);
            holder.content = (TextView) convertView.findViewById(R.id.listview_item_content_tv);
            convertView.setTag(holder);
        }else
        {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.title.setText((String) listItems.get(position).get("title"));
        holder.content.setText((String)listItems.get(position).get("content"));

        return convertView;
    }

    class ViewHolder{
        TextView title;
        TextView content;

    }
}
